package com.sgl.blog.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.thymeleaf.util.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @标题：
 * @内容：
 * @作者： 宋志豪
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException, ServletException {
        if (request.getSession().getAttribute("account") == null){
            request.setAttribute("msg",1);
            request.getRequestDispatcher("/user/login").forward(request,response);
            return false;
        }
        return true;
    }
}
